package com.xianggu.designMode.chainMethod.demo04.impl;

import com.xianggu.designMode.chainMethod.demo03.Order;
import com.xianggu.designMode.chainMethod.demo03.OrderResult;
import com.xianggu.designMode.chainMethod.demo03.impl.ObservableHandler;

public class InventoryHandler extends ObservableHandler {
    @Override
    protected OrderResult doHandle(Order order) {
        // 检查库存是否充足
        if (checkStock(order.getItemCount())) {
            return OrderResult.success();
        } else {
            // 库存不足，触发失败通知
            notifyFailure(order, "InventoryCheck");
            return OrderResult.fail("库存不足", "InventoryCheck");
        }
    }

    // 模拟库存检查逻辑
    private boolean checkStock(int required) {
        // 假设库存上限为1000
        return required <= 1000;
    }
}